/*******************************************************************************
 * Copyright (c) 2018.
 * This file was written by Fancyears·Milos·Malvis @connor. Any question/bug you can't post to 1243093366@qq.com.
 * ALL RIGHTS RESERVED.
 ******************************************************************************/
package org.fancyears.commom;

import java.awt.Font;

import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.UIManager;

import org.fancyears.helper.SkinFontHelper;
import org.jb2011.lnf.beautyeye.BeautyEyeLNFHelper;
import org.pushingpixels.substance.api.SubstanceLookAndFeel;
import org.pushingpixels.substance.api.skin.SubstanceGeminiLookAndFeel;

import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 
 * @author: Fancyears·Milos·Malvis
 * @CreateDate: 2018年12月3日 下午5:16:49
 * @Description: 带有skin的初始化器
 */

@Data
@EqualsAndHashCode(callSuper = false)
public abstract class InitializationWithSkin extends Initialization implements ISkin {
	/**
	 * 设定自定义皮肤，如果需要自定义皮肤，则设置为true并重写addSkin方法，否则将不添加skin
	 */
	private boolean customSkin = false;

	@Override
	public void run() {
		try {
			if (!customSkin) {
				defualtSkin();
			} else {
				addSkin();
			}
			init();
			createContents();
			executeShow();
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	/**
	 * 默认采用的是BeautyEye方案
	 * 
	 * @throws Exception
	 */
	private void defualtSkin() throws Exception {
		BeautyEyeLNFHelper.frameBorderStyle = BeautyEyeLNFHelper.FrameBorderStyle.generalNoTranslucencyShadow;
		BeautyEyeLNFHelper.launchBeautyEyeLNF();
		UIManager.put("RootPane.setupButtonVisible", false);
		// 如何开启/关闭窗口在不活动时的半透明效果？
		// 设置此开关量为false即表示关闭之，BeautyEye LNF中默认是true
		BeautyEyeLNFHelper.translucencyAtFrameInactive = true;
		// 调整默认字体,全部更换成微软雅黑
		for (int i = 0; i < SkinFontHelper.DEFAULT_FONT.length; i++)
			UIManager.put(SkinFontHelper.DEFAULT_FONT[i], new Font("微软雅黑", Font.PLAIN, 14));
	}

	/**
	 * 可以切换成Substance方案，切换之后需要自己手动实现addSkin方法
	 * 
	 * @throws Exception
	 */
	@SuppressWarnings("unused")
	private void defualtSkinSubstance() throws Exception {
		JFrame.setDefaultLookAndFeelDecorated(true);
		JDialog.setDefaultLookAndFeelDecorated(true);
		try {
			// 设置皮肤
			UIManager.setLookAndFeel(new SubstanceGeminiLookAndFeel());
			SubstanceLookAndFeel.setToUseConstantThemesOnDialogs(true);
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("设置主题皮肤失败");
		}
	}

	/**
	 * 设置了customSkin=true则必须自己手动实现addSkin方法，否则请继承{@link Initialization}
	 */
	@Override
	public void addSkin() throws Exception {
		throw new Exception("已设置customSkin=true却不重写addSkin方法，未基类addSkin方法，将不添加任何skin，请重写addSkin方法");
	}

	/**
	 * 设置了customShow=true则必须自己手动实现show方法，否则请继承{@link Initialization}
	 */
	@Override
	public void show() throws Exception {
		throw new Exception("已设置customShow=true却不重写show方法，未重写基类show方法，将不显示任何窗口，请重写show方法");
	}

}
